What is @turf/point-grid?
@turf/point-grid is a module from the Turf.js library that allows you to create a grid of points within a bounding box. This can be useful for various geospatial analyses, such as sampling, spatial interpolation, and creating heatmaps.
What are @turf/point-grid's main functionalities?
Create a Point Grid
This feature allows you to create a grid of points within a specified bounding box. The `bbox` parameter defines the bounding box, `cellSide` specifies the distance between points, and `options` can include units of measurement.
const turf = require('@turf/turf');
const bbox = [-96, 31, -84, 40];
const cellSide = 50;
const options = { units: 'miles' };
const pointGrid = turf.pointGrid(bbox, cellSide, options);
console.log(pointGrid);
Other packages similar to @turf/point-grid
leaflet
Leaflet is a popular open-source JavaScript library for mobile-friendly interactive maps. While it does not directly provide point grid functionality, it can be used in conjunction with other libraries to achieve similar results. Leaflet is more focused on rendering and interacting with maps rather than generating geospatial data.
d3-geo
D3-geo is a module of the D3.js library that provides geographic projections, shapes, and utilities. It can be used to create point grids, but it requires more manual setup compared to @turf/point-grid. D3-geo is more flexible and can be used for a wider range of geospatial visualizations.
geotiff
Geotiff is a library for reading and writing GeoTIFF files in JavaScript. While it does not directly create point grids, it can be used to manipulate geospatial raster data, which can then be sampled to create point grids. It is more specialized for working with raster data compared to @turf/point-grid.
@turf/point-grid
pointGrid
Creates a grid of points
Parameters
-
bbox
BBox extent of grid in [minX, minY, maxX, maxY] order
-
cellSide
number the distance between points
-
options
Object Optional parameters (optional, default {}
)
options.units
Units the units of the cellSide value. Supports all valid Turf Units (optional, default 'kilometers'
)options.mask
Feature<(Polygon | MultiPolygon)>? if passed a Polygon or MultiPolygon, the grid Points will be created only inside itoptions.properties
Object passed to each point of the grid (optional, default {}
)
Examples
var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
var cellSide = 3;
var options = {units: 'miles'};
var grid = turf.pointGrid(extent, cellSide, options);
var addToMap = [grid];
Returns FeatureCollection<Point> grid of points
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this single module individually:
$ npm install @turf/point-grid
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf